package  com.pcbly.web.business.news;

/**
* @author carl.song
* Copyright (c) 2010 Lightsoft, International.
* All rights reserved.
*
*/

import java.util.HashMap;
import java.util.List;

import com.pcbly.web.persistence.news.NewsDao;
import com.pcbly.web.persistence.table.ColumnDao;
import com.pcbly.web.bean.news.NewsBean;
import com.pcbly.web.bean.table.ColumnBean;
import com.pcbly.web.business.BaseServiceImp;
import com.pcbly.web.components.hibernate.support.Page;
import com.pcbly.web.components.form.AbstractAnalyseCommonDataExt;
import com.pcbly.web.components.form.AnalyseCommonDataExtCreate;
import com.pcbly.web.components.form.AnalyseCommonDataExtEdit;
import com.pcbly.web.components.form.AnalyseCommonDataExtView;

 
public class NewsServiceImp extends BaseServiceImp<NewsBean> implements NewsService {
	 public NewsServiceImp() {
		super();
		// TODO Auto-generated constructor stub
	}
	private NewsDao newsDao;
	
	private ColumnDao columnDao;

	public void setColumnDao(ColumnDao columnDao) {
		this.columnDao = columnDao;
	}
	
	public void setNewsDao(NewsDao newsDao) {
		this.newsDao = newsDao;
	}
	
	@Override
	public NewsBean getNewsBeanById(String id) throws Exception {
		// TODO Auto-generated method stub
		return newsDao.get(NewsBean.class,id);
	}
	
	@Override
	public void removeNewsBeanById(String id) throws Exception{
		newsDao.removeNewsBeanById(id);
	}
	
	@Override
	public void removeNewsBeanByIds(String ids) throws Exception{
		newsDao.removeNewsBeanByIds(ids);
	}
	
	
	@Override
	public NewsBean saveNewsBean(NewsBean news) throws Exception{
		return newsDao.saveNewsBean(news);
	}
	
	@Override
	public NewsBean updateNewsBean(NewsBean news) throws Exception{
		newsDao.saveObject( news);
		return news;
	}
	public Page<NewsBean>  findNewsBeanByCond(NewsBean bean,
			Page<NewsBean> page, String orderByName, boolean asc)
			throws Exception{
		return newsDao.findNewsBeanByCond(
				bean, page, orderByName, asc);
	}
	
	@Override
	public String findNewsBeanExtCreate(String tableName) throws Exception {
		// TODO Auto-generated method stub
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtCreate();
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findNewsBeanExtEdit(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = newsDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtEdit();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findNewsBeanExtView(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = newsDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtView();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public void saveNewsBeanExt(String sql) throws Exception {
		// TODO Auto-generated method stub
		newsDao.saveCommnonDataBeanExt(sql);
	}

	@Override
	public boolean getHasNewsBeanExtData(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		return newsDao.getHasCommnonDataBeanExt(tableName, id);
	}
}
